<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {$LOAD_STYLE.top|raw}
</head>
<script src="__JS__/clipboard.min.js"></script>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">         
                       <div class="layui-form-item layui-inline">
                           <label class="layui-form-label">面料编号</label>
                           <div class="layui-input-inline">
                               <input type="text" name="fabric_code" placeholder="例如:6688" class="layui-input">
                           </div>
                       </div>   
                       <div class="layui-form-item layui-inline">
                           <label class="layui-form-label">面料名称</label>
                           <div class="layui-input-inline">
                               <input type="text" name="fabric_name" placeholder="例如:精棉拉架" class="layui-input">
                           </div>
                       </div>
                       
                       <div class="layui-form-item layui-inline">
                           <label class="layui-form-label">面料类型</label>
                           <div class="layui-input-inline">
                       	<select name="fabric_type">
                       		<option value="" selected>不限</option>
                       		<option value="1">门市产品</option>
                       		<option value="2">临时产品</option>
                       	</select>
                           </div>
                       </div>
                       
                         <div class="layui-form-item layui-inline">
                             <label class="layui-form-label">备注</label>
                             <div class="layui-input-inline">
                                 <input type="text" name="remark" placeholder="" class="layui-input">
                             </div>
                         </div>
                   </div>
                    <div class="layui-form-item">
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">供应编号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sup_code" placeholder="供应编号" class="layui-input">
                            </div>
                        </div>
                        
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">供应商</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sup_name" placeholder="例如:东盛" class="layui-input">
                            </div>
                        </div>
                        
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">色卡顺序</label>
                            <div class="layui-input-inline">
                        	<select name="is_change">
                        		<option value="" selected>不限</option>
                        		<option value="0">相同</option>
                        		<option value="1">改动</option>
                        	</select>
                            </div>
                        </div>
                        
                        <div class="layui-form-item layui-inline">
                               <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                                   <i class="layui-icon layui-icon-search"></i>
                                   查询
                               </button>
                               <button type="reset" class="pear-btn pear-btn-md">
                                   <i class="layui-icon layui-icon-refresh"></i>
                                   重置
                               </button>
                        </div>
                    </div>
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="dataTable" lay-filter="dataTable"></table>
			</div>
		</div>

		<script type="text/html" id="toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
			</button>
			<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
            <button class="pear-btn pear-btn-md" lay-event="recycle">
		        <i class="layui-icon layui-icon-delete"></i>
		        回收站
		    </button>
            
            <button class="pear-btn pear-btn-md" lay-event="copy">
                <i class="layui-icon layui-icon-file-b"></i>
                复制产品
            </button>
		</script>
        
        <script type="text/html" id="fabric_name">
            <div copy="{{d.info_tpl}}">
                <a href="javascript:;" title="{{d.info_tpl}}">
                {{d.fabric_name}}
                </a>
            </div>
        </script>
        
        <script type="text/html" id="sup_code">
            <div copy="{{d.sup_code}}">
                <a href="javascript:;" title="点击复制信息">{{ d.sup_code }}</a>
            </div>
        </script>

        <script type="text/html" id="fabric_type">
          {{#  if(d.fabric_type == 1){ }}
            <span class="layui-tag pear-btn-green">门市</span>
          {{#  }else if(d.fabric_type == 2){ }}
            <span class="layui-tag pear-btn-grey">临时</span>
          {{#  } }}
        </script>
        
        <script type="text/html" id="bulk_payment">
          {{#  if(d.bulk_payment == 1){ }}
            <span class="layui-tag pear-btn-grey">现</span>
          {{#  }else if(d.bulk_payment == 2){ }}
            <span class="layui-tag pear-btn-red">欠</span>
          {{#  } }}
        </script>
        
        <script type="text/html" id="is_change">
          {{#  if(d.is_change == 0){ }}
            <span class="layui-tag pear-btn-grey">否</span>
          {{#  }else if(d.is_change == 1){ }}
            <span class="layui-tag pear-btn-red">改</span>
          {{#  } }}
        </script>
        
           <script type="text/html" id="status">
               <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="status" {{# if(d.status==1){ }} checked {{# } }}>
           </script>

		<script type="text/html" id="options">
            <button class="pear-btn pear-btn-warming pear-btn-sm" lay-event="pop" url="{:U('fabric.color/add')}/fabric_id/{{d.id}}" poptitle="添加【{{d.fabric_code}} - {{d.fabric_name}}】颜色" title="添加颜色"><i class="layui-icon layui-icon-add-1"></i></button>
            <button class="pear-btn pear-btn-ext1 pear-btn-sm" lay-event="pop" url="{:U('fabric.color/table')}/fabric_id/{{d.id}}" poptitle="【{{d.fabric_code}} - {{d.fabric_name}}】颜色库" title="颜色库" popsize="1"><i class="layui-icon layui-icon-theme"></i></button>
			<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button>
		    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
		</script>
        <script>
        layui.use(['jquery','common','mycomm','table'], function() {
            let $ = layui.jquery;
			let common = layui.common;
			let mycomm = layui.mycomm;
			let table = layui.table;
            let $table_name = "dataTable";
            let MODULE_PATH = "{$MODULE_PATH}";
            
            let cols = [
                [{
                        type: 'checkbox',
                    }, {
                        field: "id",
                        title: "面料ID",
                        width: 90,
                        hide:true,
                        unresize: "true",
                        align: "center",
                    }, {
                        field: "sup_id",
                        title: "供应商ID",
                        width: 90,
                        hide:true,
                        unresize: "true",
                        align: "center",
                    }, {
                        field: "is_change",
                        title: "改色",
                        width: 90,
                        unresize: "true",
                        align: "center",
                        templet:"#is_change"
                   }, {
                       field: "sup_name",
                       title: "供应商",
                       width: 100,
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "fabric_code",
                       title: "面料编号",
                       width: 100,
                       unresize: "true",
                       align: "center",
                   }, {
                       field: "fabric_name",
                       title: "面料名称",
                       width: 180,
                       // edit: 'text',
                       unresize: "true",
                       align: "left",
                       templet: '#fabric_name',
                    }, {
                        field: "sup_code",
                        title: "供应编号",
                        width: 90,
                        unresize: "true",
                        // edit: 'text',
                        align: "center",
                        templet: "#sup_code",
                    }, {
                        field: "width",
                        title: "幅宽",
                        width: 80,
                        templet: "<div>{{d.width}}cm</div>",
                        hide:true,
                        unresize: "true",
                        align: "center"
                       }, {
                        field: "weight",
                        title: "克重",
                        width: 120,
                        templet: "<div>{{d.weight}}g</div>",
                        unresize: "true",
                        align: "center",
                   }, {
                       field: "kgm",
                       title: "kg/m",
                       width: 70,
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "tube",
                       title: "管+空",
                       width: 80,
                       unresize: "true",
                       templet: "<div>{{d.tube}} + {{d.empty_diff}}</div>",
                       align: "center",
                   }, {
                       field: "bulk_price",
                       title: "大货价",
                       width: 80,
                       hide: true,
                       unresize: "true",
                       align: "center",
                   }, {
                       field: "cut_price",
                       title: "剪板",
                       width: 80,
                       hide: true,
                       unresize: "true",
                       align: "center"
                   }, {
                       field: "composition",
                       title: "成分",
                       width: 400,
                       hide: true,
                       unresize: "true",
                       align: "left"
                   }, {
                       field: "sup_tube",
                       title: "供应空差",
                       width: 110,
                       unresize: "true",
                       align: "center",
                       templet: "<div>{{d.sup_tube}} + {{d.sup_empty}} - {{d.return_diff}}</div>",
                    },{
                       field: "fabric_type",
                       title: "面料类型",
                       width: 100,
                       unresize: "true",
                       hide:true,
                       align: "center",
                       templet: '#fabric_type',
                   }, {
                       field: "status",
                       title: "状态",
                       width: 100,
                       hide:true,
                       unresize: "true",
                       align: "center",
                       templet:"#status",
                    }, {
                        field: "exp_method",
                        title: "提货方式",
                        width: 100,
                        unresize: "true",
                        align: "center",
                    }, {
                        field: "exp_name",
                        title: "物流",
                        width: 60,
                        unresize: "true",
                        align: "center",
                    }, {
                        field: "bulk_payment",
                        title: "结算",
                        width: 70,
                        unresize: "true",
                        align: "center",
                        templet:"#bulk_payment",
                   }, {
                       field: "remark",
                       title: "备注",
                       edit: 'text',
                       unresize: "true",
                       align: "center"
                   }, {
                        title: '操作',
                        toolbar: '#options',
                        unresize: true,
                        align: 'center',
                        width:200,
                    }
                ]
            ]
			
			mycomm.tableInit('{$controller_title}',MODULE_PATH,cols);
            
            mycomm.tableToolBar('{$controller_title}',MODULE_PATH,$table_name,function(obj){
            	if(obj.event === "copy"){
            		var ids=isSelect(table,$table_name);
            		if(ids){
            			// load_show('复制数据中...');
            			copyCloth(ids);
            		}else{
            			return false;
            		}
            	}
            });
            
            //复制产品
            function copyCloth(ids){
            	var url="{:U('fabric.main/copy')}";
            	var data={
            		ids:ids
            	};
            	$.post(url,data,function(res){
            		if(res.code==200){
            			if(res.data.status==1){
            				load_hide();
            				Alert(res.msg,'success',1);
            				table.reload($table_name);
            			}else{
            				load_hide();
            				Alert(res.msg,'error',3);
            			}
            		}else{
            			load_hide();
            			Alert(res.msg,'error',3);
            		}
            	});
            }
            
            // 是否选中产品
            function isSelect(table,table_name){
            	let data = table.checkStatus(table_name).data;
            	if (data.length === 0) {
            		Alert('未选中数据','info',1.5);
            		return false;
            	}
            	var ids = [];
            	var hasCheck = table.checkStatus(table_name)
            	var hasCheckData = hasCheck.data
            	if (hasCheckData.length > 0) {
            		$.each(hasCheckData, function (index, element) {
            			ids.push(element.id)
            		})
            	}
            	ids=ids.join('|');
            	return ids;
            }
        })
    </script>
	{$LOAD_STYLE.bottom|raw}
	</body>
</html>
